<!--
 * @Description: App
 * @Author: xinqiao lxq1990.0716@qq.com
 * @Date: 2023-03-30
 * @LastEditors: xinqiao lxq1990.0716@qq.com
 * @LastEditTime: 2025-06-12
-->
<script lang="ts" setup>
  import 'dayjs/locale/zh-cn'

  import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
  import { ConfigProvider, Modal } from 'ant-design-vue'
  import zhCN from 'ant-design-vue/es/locale/zh_CN'
  import dayjs from 'dayjs'
  import { createVNode, onMounted } from 'vue'

  import { isDevMode } from './utils/env'
  import { getUpdateManager } from './utils/updater'

  dayjs.locale(zhCN.locale)

  onMounted(() => {
    if (!isDevMode()) getUpdate()
  })

  let modal

  /**
   * 更新版本
   */
  const getUpdate = () => {
    const up = getUpdateManager({})
    up.on('update', () => {
      if (modal) return
      modal?.destroy()
      modal = Modal.confirm({
        title: '发现新版本，是否更新？',
        icon: createVNode(ExclamationCircleOutlined),
        okText: '更新',
        cancelText: '取消',
        onOk() {
          location.reload()
          modal = null
        },
        onCancel() {
          up.remove('update')
          modal = null
        },
      })
    })
  }
</script>

<template>
  <ConfigProvider
    :locale="zhCN"
    :theme="{
      token: {
        colorPrimary: '#4599FA',
        borderRadius: 4,
      },
    }"
  >
    <router-view />
  </ConfigProvider>
</template>

<style type="less">
  .ant-modal div[aria-hidden='true'] {
    display: none !important;
  }
</style>
